from selenium import webdriver
from selenium.webdriver.common.by import By
import time

def login():
    # 获取文本框的对象
    username = browser.find_element(By.ID, "j_username")
    username.send_keys("ZLIU217")
    password = browser.find_element(By.NAME, "j_password")
    password.send_keys("ZLIU@qwe217")
    loginButton = browser.find_element(By.NAME, "Submit")
    loginButton.click()


def builder():
    global select
    java = browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[2]/table/tbody/tr[6]/td[3]/a")
    print(java.get_attribute("href"))
    browser.get(java.get_attribute("href"))
    k8s = browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[3]/table/tbody/tr/td[3]/a")
    browser.get(k8s.get_attribute("href"))
    dev = browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[3]/table/tbody/tr[1]/td[3]/a")
    browser.get(dev.get_attribute("href"))
    cloud = browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[3]/table/tbody/tr[2]/td[3]/a")
    browser.get(cloud.get_attribute("href"))
    k8scloud = browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[3]/table/tbody/tr/td[3]/a")
    browser.get(k8scloud.get_attribute("href"))


def builder2(projectName,gitBranch):
    browser.find_element(By.XPATH, "/html/body/div[4]/div[1]/div[1]/div[3]/span/a").click();
    select = browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/form/div[1]/div[4]/div[3]/div/input[2]")
    select.send_keys(projectName)
    browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/form/div[1]/div[7]/div[3]/div/div/input").send_keys(
        gitBranch)
    # browser.find_element(By.XPATH, "/html/body/div[4]/div[2]/form/div[1]/div[8]/div[3]/div/select").send_keys("true")
    time.sleep(2)
    browser.find_element(By.ID, "yui-gen1-button").submit()

# 创建浏览器对象
browser = webdriver.Chrome()
# url
url = 'https://artops.digitalvolvo.com/volvo-jenkins/login?from=%2Fvolvo-jenkins%2F'
browser.get(url)
print("start")
time.sleep(1)

login()

time.sleep(1)

builder()

# projectList = ["domain-boutique-center",'app-boutique-management','bff-volvoworks-boutique']
# projectList = ['app-boutique-management','bff-volvoworks-boutique']
projectList = ["domain-boutique-center"]
# projectList = ["bff-volvoworks-boutique"]
# projectList = ["oem-boutique-service"]
# projectList = ["app-boutique-management"]
# projectList = ["mall-inner-bff","app-mall-inner-management","domain-mall-inner"]


for e in projectList:
    print(e)
    # builder2(e, "feature-20231106")
    builder2(e, "feature-20240311")
    time.sleep(2)
# 退出
# browser.quit()

time.sleep(60*100)